//------------------------------------------------------------------------------
#include "CMyTextEdit.h"
#include "CTextEditDelegate.h"
//------------------------------------------------------------------------------
CTextEditDelegate::CTextEditDelegate(QObject *parent) : QItemDelegate(parent)
{
}
//------------------------------------------------------------------------------
QWidget * CTextEditDelegate::createEditor(	QWidget *parent, const QStyleOptionViewItem &option,
											const QModelIndex &index) const
{
	CMyTextEdit *editor=new CMyTextEdit(parent);
	editor->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
	
	return editor;
}
//------------------------------------------------------------------------------
void CTextEditDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
	QString value=index.model()->data(index, Qt::EditRole).toString();
	
	CMyTextEdit *textEdit=static_cast<CMyTextEdit *>(editor);
	//textEdit->setValue(value);
	textEdit->setText(value);
}
//------------------------------------------------------------------------------
void CTextEditDelegate::setModelData(	QWidget *editor, QAbstractItemModel *model,
										const QModelIndex &index) const
{
	CMyTextEdit *textEdit=static_cast<CMyTextEdit *>(editor);
	//QString value=textEdit->getValue();
	QString value=textEdit->toPlainText();
	model->setData(index, value, Qt::EditRole);
}
//------------------------------------------------------------------------------
void CTextEditDelegate::updateEditorGeometry(	QWidget *editor,
												const QStyleOptionViewItem &option,
	   											const QModelIndex &index) const
{
	editor->setGeometry(option.rect);
}
//------------------------------------------------------------------------------